X=imread('wed2.jpg');
Xoriginal=X(1:600,1:600,:);
f1=figure;
set(f, 'name', 'Original 600x600','numbertitle','off')
imagesc(Xoriginal);
axis square
r=X(:,:,1);g=X(:,:,2);b=X(:,:,3);
Y = 0.299*r + 0.587*g + 0.114*b;
U = b - Y;
V = r - Y;
QY = [16, 11, 10, 16, 24, 40, 51, 61;
12, 12, 14, 19, 26, 58, 60, 55;
14, 13, 16, 24, 40, 57, 69, 56;
14, 17, 22, 29, 51, 87, 80, 62;
18, 22, 37, 56, 68, 109, 103, 77;
24, 35, 55, 64, 81, 104, 113, 92;
49, 64, 78, 87, 103, 121, 120, 101;
72, 92, 95, 98, 112, 100, 103, 99];
QC = 50.*[
17, 18, 24, 47, 99, 99, 99, 99;
18, 21, 26, 66, 99, 99, 99, 99;
24, 26, 56, 99, 99, 99, 99, 99;
47, 66, 99, 99, 99, 99, 99, 99;
99, 99, 99, 99, 99, 99, 99, 99;
99, 99, 99, 99, 99, 99, 99, 99;
99, 99, 99, 99, 99, 99, 99, 99;
99, 99, 99, 99, 99, 99, 99, 99];
for i=1:75
for j=1:75
x=Y((i-1)*8+1:(i-1)*8+8,(j-1)*8+1:(j-1)*8+8);
xd=double(x);
xc=xd-128;
Z=dct(dct(xc')');
Zq=round(Z./QY);
Zdq=Zq.*QY;
Ydq=idct2(Zdq);
Ye=Ydq+128;
Yout((i-1)*8+1:(i-1)*8+8,(j-1)*8+1:(j-1)*8+8)=Ye;
end
end
for i=1:75
for j=1:75
x=U((i-1)*8+1:(i-1)*8+8,(j-1)*8+1:(j-1)*8+8);
xd=double(x);
xc=xd-128;
Z=dct(dct(xc')');
Zq=round(Z./QC);
Zdq=Zq.*QC;
Udq=idct2(Zdq);
Ue=Udq+128;
Uout((i-1)*8+1:(i-1)*8+8,(j-1)*8+1:(j-1)*8+8)=Ue;
end
end
for i=1:75
for j=1:75
x=V((i-1)*8+1:(i-1)*8+8,(j-1)*8+1:(j-1)*8+8);
xd=double(x);
xc=xd-128;
Z=dct(dct(xc')');
Zq=round(Z./QC);
Zdq=Zq.*QC;
Vdq=idct2(Zdq);
Ve=Vdq+128;
Vout((i-1)*8+1:(i-1)*8+8,(j-1)*8+1:(j-1)*8+8)=Ve;
end
end
R = Vout + Yout;
B = Uout + Yout;
G =(Yout - 0.299*R - 0.114*B)/0.587;
Xout(:,:,1)=uint8(R);
Xout(:,:,2)=uint8(G);
Xout(:,:,3)=uint8(B);
f2=figure;
set(f2,'name', 'Color JPEG suggested Matrix, p=1','numbertitle','off');
imagesc(Xout);
axis square;
f3=figure;
set(f3,'name', 'Comparison with p=1','numbertitle','off');
h = imshowpair(Xoriginal,Xout,'diff')
axis square;
h =
877.0015